<?php

namespace App\Providers;

use Illuminate\Http\Response;
use Illuminate\Support\ServiceProvider;

class ResponseApiProvider extends ServiceProvider
{
    /**
     * Register services.
     *
     * @return void
     */
    public function register()
    {
        //
        Response::macro('success', function($code = 0, $data=array(), $msg='success', $status=200){
            $content = [
                'code'  => $code,
                'message'  => $msg,
                'result'  => $data
            ];
            return response()->json($content, $status);
        });
        Response::macro('noContent', function($headers = []){
            return response()->noContent(Response::HTTP_NO_CONTENT, $headers);
        });
        Response::macro('failed', function($msg='failed', $status=400){
            $content = [
                'message'  => $msg
            ];
            return response()->json($content, $status);
        });
    }

    /**
     * Bootstrap services.
     *
     * @return void
     */
    public function boot()
    {
        //
    }
}
